package com.sibu.yx.promotion.admin.web.util;
import com.doubo.common.crypto.DESInstance;
import com.doubo.common.threadlocal.SerialNo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PasswordDecrypter {
    private static final Logger log = LoggerFactory.getLogger(PasswordDecrypter.class);
    private DESInstance encrypter;

    public PasswordDecrypter() {
        this.encrypter = new DESInstance();
    }

    public PasswordDecrypter(String key) {
        this.encrypter = new DESInstance(key);
    }

    public String decrypt(String encryptedString) throws Exception  {
        try {
            String decrypted = this.encrypter.decrypt(encryptedString);
            return decrypted;
        } catch (Exception var3) {
            log.error("encryptedString[{}] ##[{}][DES decrypt ERROR] Error enountered during decryption - validate decryption algorithm & key match that used for encryption", encryptedString, SerialNo.getSerialNo());
            throw new Exception (var3.getMessage());
        }
    }

    public String encrypt(String message) throws Exception  {
        try {
            String ecrypted = this.encrypter.encrypt(message);
            return ecrypted;
        } catch (Exception var3) {
            log.error("[{}][DES encrypt ERROR] Error enountered during ecryption - validate ecryption algorithm", SerialNo.getSerialNo());
            throw new Exception (var3.getMessage());
        }
    }

    public static void main(String[] ars)throws  Exception {
        PasswordDecrypter passwordDecrypter = new PasswordDecrypter("$)(#@Si&^%.Bu+=!");
        String data = "root";
        System.out.println(data + "==" + passwordDecrypter.encrypt(data));
        data = "Aa123456";
        System.out.println(data + "==" + passwordDecrypter.encrypt(data));
        data = "123456";
        System.out.println(data + "==" + passwordDecrypter.encrypt(data));
        data = "sibu_wesale";
        System.out.println(data + "==" + passwordDecrypter.encrypt(data));
        data = "sibu_integralmall";
        System.out.println(data + "==" + passwordDecrypter.encrypt(data));
        data = "09NWaUZUNjjr0IRCYzm3";
        System.out.println(data + "==" + passwordDecrypter.encrypt(data));
        data = "GRbUEjlFfVrEv1nYK+DfdA==";
        System.out.println(data + "==" + passwordDecrypter.decrypt(data));
        data = "Z/r8C+GcIw6eTEQp5T8tUWSjKGl68kov";
        System.out.println(data + "==" + passwordDecrypter.decrypt(data));
        data = "uAVRJHvlUio5oNjuqlTrGA==";
        System.out.println(data + "==" + passwordDecrypter.decrypt(data));
        data = "Z/r8C+GcIw6eTEQp5T8tUWSjKGl68kov";
        System.out.println(data + "==" + passwordDecrypter.decrypt(data));
        data = "+lFNfjMaqWr1i45OvFjYeg==";
        System.out.println(data + "==" + passwordDecrypter.decrypt(data));


    }
}